package org.oos.atom.elements;

import java.io.Serializable;

import org.oos.util.Log;

import com.google.api.client.util.Key;

/**
 * This class represents an Area identity as a bean with a Factory method
 * (create) to initiate values of it using a fly-weight design
 * 
 * @author pablo.gonzalez@11870.com
 * 
 */
public class Area implements Serializable, Cloneable {

	private static final long serialVersionUID = -5621755894280495192L;

	@Key("text()")
	private String name;

	@Key("@slug")
	private String slug;

	private static Area flyweight;

	public static Area create(String name, String slug) {
		Area area;
		if (flyweight == null) {
			flyweight = new Area();
		}
		try {
			area = (Area) flyweight.clone();
		} catch (CloneNotSupportedException e) {
			Log.e(e);
			area = new Area();
		}
		area.setName(name);
		area.setSlug(slug);
		return area;
	}

	public Area() {
		// Default constructor
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSlug() {
		return slug;
	}

	public void setSlug(String slug) {
		this.slug = slug;
	}

	@Override
	public Area clone() throws CloneNotSupportedException {
		return (Area) super.clone();
	}

	@Override
	public String toString() {
		return name + ": {" + slug + "}";
	}

}
